gesturestylus: Retrieve event and controller widget only once
authorTimm Bäder <mail@baedert.org>
Fri, 25 Dec 2020 08:58:04 +0000 (09:58 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 3 Jan 2021 10:01:28 +0000 (11:01 +0100)
Make it clear that these are not gonna chance while iterating the loop.

gtk/gtkgesturestylus.c

index 2d49783baf399e821c9e3fee1025af052b9e4ecb..d6ac7e166c77195026d8fb976859fb72a32c5e5f 100644 (file)
@@ -322,6 +322,8 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
   guint n_coords = 0, i;
   double surf_x, surf_y;
   GtkNative *native;
+  GtkWidget *event_widget;
+  GtkWidget *controller_widget;
 
   g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
   g_return_val_if_fail (backlog != NULL && n_elems != NULL, FALSE);
@@ -338,6 +340,8 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
   gtk_native_get_surface_transform (native, &surf_x, &surf_y);
 
   backlog_array = g_array_new (FALSE, FALSE, sizeof (GdkTimeCoord));
+  event_widget = gtk_get_event_widget (event);
+  controller_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
   for (i = 0; i < n_coords; i++)
     {
       GdkTimeCoord *time_coord = &history[i];
@@ -345,9 +349,7 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
 
       g_array_append_val (backlog_array, *time_coord);
       time_coord = &g_array_index (backlog_array, GdkTimeCoord, backlog_array->len - 1);
-
-      if (gtk_widget_compute_point (GTK_WIDGET (native),
-                                    gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
+      if (gtk_widget_compute_point (event_widget, controller_widget,
                                     &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X] - surf_x,
                                                           time_coord->axes[GDK_AXIS_Y] - surf_y),
                                     &p))